<template>
	<view>
		<view class="search">
			<!-- search模块 -->
			<view class="oneline">
				<!-- 选择问帖人 -->
				<view class="left">
					<view class="content">
						<view class="center">
							<view class="imgs">
								<image src="@/static/socialized-service/specialist-consultation/search/user.png"
									class="img" mode="aspectFit">
								</image>
							</view>
							<picker @change="personChange" :range="userList" range-key="nickName">
								<view class="text">
									{{nickName}}
								</view>
							</picker>
						</view>
						<uni-icons type="close" color="#cccbce" @click="clearUser"></uni-icons>
					</view>

				</view>
				<!-- 关键词 -->
				<view class="right">
					<view class="content">
						<view class="center">
							<view class="imgs">
								<image src="@/static/socialized-service/specialist-consultation/search/keyword.png"
									class="img" mode="aspectFit">
								</image>
							</view>
							<uni-easyinput class="uni-mt-5" v-model="collectData.invitationTitle" :inputBorder="false"
								placeholder="请输入关键字">
							</uni-easyinput>
						</view>
					</view>
				</view>
			</view>
			<view class="twoline">
				<!-- 选择日期 -->
				<view class="twoleft">
					<view class="content">
						<view class="center">
							<view class="imgs">
								<image src="@/static/socialized-service/specialist-consultation/search/time.png"
									class="img" mode="aspectFit">
								</image>
							</view>
							<uni-datetime-picker v-model="range" type="datetimerange" start="2023-1-1" :end="end"
								rangeSeparator="至" :clearIcon="true" :border="false" @change="selectTime"></uni-datetime-picker>
						</view>
						<!-- <uni-icons type="close" color="#cccbce"></uni-icons> -->
					</view>
				</view>
				<view class="tworight">
					<view class="btn" @click="goSearch">搜索</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 查询池
	import postApi from '@/api/socialized-servce/specialist-consultation/user-module/consultation-list/index.js'
	// 专家端诊断贴
	import diagnosticListApi from '@/api/socialized-servce/specialist-consultation/expert-module/diagnostic-list/index.js'
	// 我的诊断
	import myDiagnosticListApi from '@/api/socialized-servce/specialist-consultation/expert-module/my-diagnosis/index.js'
	// 我的诊断
	import myPostApi from '@/api/socialized-servce/specialist-consultation/user-module/my-interrogation/index.js'
	export default {
		name: 'Work-manage',
		data() {
			return {
				userList: [], //用户列表
				range: ["", ""],
				start: Date.now(),
				end: Date.now() + 1000000000,
				// 收集数据
				time: '选择日期',
				nickName: '选择问帖人', //问帖人
				collectData: {
					publisherId: '',
					invitationTitle: '', //关键词
					beginTime: null,
					endTime: null,
					invitationTypeId: this.invitationTypeId
				}
			}
		},
		props: ['invitationTypeId', 'module', 'state'],
		created() {
			this.getAllUser()
		},
		onShow() {

		},
		watch: {
			// 分类切换
			invitationTypeId: {
				immediate: true,
				handler() {
					this.nickName = '选择问帖人'
					this.collectData.invitationTypeId = this.invitationTypeId
					this.collectData.beginTime = null
					this.collectData.endTime = null
					this.collectData.invitationTitle = ''
					this.collectData.publisherId = ''
					this.range = []
				}
			},
		},
		methods: {
			// 获取所有用户
			async getAllUser() {
				let params = {userType: 'custom_user'}
				let {
					data: res
				} = await postApi.queryUser(params)
				this.userList = res
			},
			// 选择用户
			personChange(e) {
				this.collectData.publisherId = this.userList[e.detail.value].userId
				this.nickName = this.userList[e.detail.value].nickName
			},
			// 选择时间范围
			selectTime(e) {
				console.log(e);
				console.log(this.range);
				this.collectData.beginTime = e[0]
				this.collectData.endTime = e[1]
			},
			// 搜索按钮
			async goSearch() {
				if (this.module === 'user') {
					let res = await postApi.queryQualifiedPost(this.collectData)
					if (res.code == 200) {
						// console.log(res.data);
						this.$emit('shareSearchList', res.data)
					}
				} else if (this.module === 'expert1') {
					let params = {
						page: 1,
						size: 10,
						condition: {
							invitationTypeId: this.invitationTypeId,
							beginTime: this.collectData.beginTime,
							endTime: this.collectData.endTime,
							publisherId: this.collectData.publisherId,
							invitationTitle: this.collectData.invitationTitle,
							serviceProviderNo: uni.getStorageSync('serviceProviderNo')
						}
					}
					let res = await diagnosticListApi.queryPageDiagnostic(params)
					if (res.code == 200) {
						this.$emit('shareSearchList', res.data.content,1)
					}
				} else if (this.module === 'expert2') {
					let params = {
						page: 1,
						size: 10,
						condition: {
							beginTime: this.collectData.beginTime,
							endTime: this.collectData.endTime,
							publisherId: this.collectData.publisherId,
							invitationTitle: this.collectData.invitationTitle
						}
					}
					let res = await myDiagnosticListApi.queryMyDiagnosticList(params)
					if (res.code == 200) {
						// console.log(res.data);
						this.$emit('shareSearchList', res.data.content,1)
					}
				} else if (this.module === 'user1') {
					let params = {
						beginTime: this.collectData.beginTime,
						endTime: this.collectData.endTime,
						publisherId: this.collectData.publisherId,
						invitationTitle: this.collectData.invitationTitle
					}
					if (this.state == 1) {
						console.log('w',params);	
						this.getMyPostList(params)
					} else if (this.state == 2) {
						params['resolveFlag'] = false
						this.getUnresolvePost(params)
					} else {
						params['resolveFlag'] = true
						this.getResolvePost(params)
					}
				}
				// 这里需要判断是哪个夫组件
			},
			// 全部问诊
			async getMyPostList(params) {
				let res = await myPostApi.queryPostList(params)
				console.log(res, 'all');
				if (res.code === 200) {
					this.$emit('shareSearchList', res.data)
				}
			},
			// 未解决问诊
			async getUnresolvePost(params) {
				let res = await myPostApi.queryPostList({
					resolveFlag: false,
					...params
				})
				if (res.code == 200) {
					this.$emit('shareSearchList', res.data)
				}
			},
			// 已解决
			async getResolvePost(params) {
				let res = await myPostApi.queryPostList({
					resolveFlag: true,
					...params
				})
				if (res.code == 200) {
					this.$emit('shareSearchList', res.data)
				}
			},
			clearUser() {
				this.nickName = '选择问帖人'
				this.collectData.publisherId = ''
			},
			// clearTitle() {
			// 	this.collectData.invitationTitle = ''
			// }

		}
	}
</script>

<style lang="scss" scoped>
	.search {
		width: 95%;
		padding-top: 16rpx;
		padding-right: 30rpx;
		align-items: center;
		justify-content: center;
		background-color: #F5F6FA;

		.oneline,
		.twoline {
			position: relative;
			display: flex;
			margin-left: 30rpx;
			padding: 0 20rpx;
			height: 80rpx;
			border-radius: 60rpx;
			background-color: rgba(255, 255, 255, 1);
			border: 1px solid rgba(0, 0, 0, 0.05);
			box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.05);
			justify-content: center;
			align-items: center;
			margin-bottom: 10rpx;

			.left,
			.twoleft {
				display: flex;
				flex: 50%;
				color: #FFFFFF;
				height: 50rpx;
				border-right: 4rpx #cccbce solid;
				margin-left: 5rpx;
				padding-right: 10rpx;
				font-size: 30rpx;

				.content {
					color: #959497;
					height: 50rpx;
					white-space: nowrap;
					font-weight: 600;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.center {
						display: flex;
						justify-content: center;
						align-items: center;

						.imgs {
							width: 50rpx;
							height: 50rpx;
							margin-right: 10rpx;

							.img {
								width: 100%;
								height: 100%;
							}
						}

						.text {
							width: 190rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

					}
				}
			}

			.twoleft {
				flex: 80%;
			}

			.right,
			.tworight {
				flex: 50%;
				height: 50rpx;
				color: #959497;
				padding-right: 10rpx;
				white-space: nowrap;
				font-weight: 600;
				font-size: 30rpx;

				.content {
					color: #959497;
					height: 50rpx;
					margin-left: 10rpx;
					white-space: nowrap;
					font-weight: 600;
					display: flex;
					justify-content: space-between;
					align-items: center;
				}

				.center {
					display: flex;
					justify-content: center;
					align-items: center;

					.imgs {
						margin-right: 10rpx;
						width: 50rpx;
						height: 50rpx;

						.img {
							width: 100%;
							height: 100%;
						}

					}

					.keyword {
						height: 50rpx;
					}

					// .search-input-view {
					// 	display: flex;
					// 	margin-left: 50rpx;
					// 	align-items: center;
					// 	// margin-bottom: 20rpx;
					// 	height: 50rpx;
					// 	// width: calc(100% - 24rpx);
					// 	// padding: 0 10rpx;
					// 	border-radius: 40rpx;
					// 	background-color: #FFFFFF;
					// 	box-shadow: 0rpx 0rpx 16rpx 2rpx rgba(0, 0, 0, 0.05);

					// 	.uni-mt-5 {
					// 		height: 50rpx;
					// 		width: calc(100% - 178rpx);
					// 		color: #959595;
					// 		font-size: 32rpx;
					// 		display: flex;
					// 		justify-content: center;
					// 	}
					// }

				}

				.btn {
					position: absolute;
					top: 50%;
					transform: translateY(-50%);
					z-index: 66;
					width: 124rpx;
					height: 64rpx;
					margin-left: 8rpx;
					font-size: 28rpx;
					line-height: 64rpx;
					text-align: center;
					color: #FFFFFF;
					background: linear-gradient(18deg, #43A2FF 0%, #62B1FF 100%);
					border-radius: 40rpx 40rpx 40rpx 40rpx;
					opacity: 1;
				}
			}

			.tworight {
				flex: 20%;
				cursor: pointer;
			}

			.searchbutton {
				flex: 1;
				width: 20%;
				background: linear-gradient(18deg, #43A2FF 0%, #62B1FF 100%);
				border-radius: 40rpx;
				box-shadow: none;
				margin-left: 10rpx;
				font-size: 28rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

	}

	// ::v-deep .uni-date-editor--logo {
	// 	display: none;
	// }
	::v-deep .uniui-calendar:before {
		content: '';
		color: #0480FB;
	}

	::v-deep .uni-date__x-input {
		padding-left: 0;
		width: 170rpx;
	}
</style>